package com.zelin.shop.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zelin.entity.GoodsEntity;
import com.zelin.entity.group.Goods;
import com.zelin.sellergoods.service.GoodsService;
import com.zelin.utils.PageUtils;
import com.zelin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 
 *
 * @author WF
 * @email 2568783935@qq.com
 * @date 2021-07-23 21:10:35
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Reference(timeout = 5000)
    private GoodsService goodsService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("manager:goods:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		GoodsEntity goods = goodsService.getById(id);

        return R.ok().put("goods", goods);
    }

    /**
     * 功能: 根据id查询得到复合商品对象
     * 参数:
     * 返回值: com.zelin.utils.R
     * 时间: 2021/7/30 12:38
     */
    @RequestMapping("/findById/{id}")
    public R findById(@PathVariable("id") Long id){
        Goods goods = goodsService.findById(id);
        return R.ok().put("goods", goods);
    }
    /**
     * 保存
     */
    @PostMapping(value="/save")
    public R save(@RequestBody Goods data){
        System.out.println("goods = " + data);
		goodsService.saveGoods(data);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("manager:goods:update")
    public R update(@RequestBody Goods goods){
		goodsService.update(goods);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("manager:goods:delete")
    public R delete(@RequestBody Long[] ids){
		goodsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
